home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / pj64.arc / TV_VIDEO.C < prev    next >
C/C++ Source or Header  |  1988-12-16  |  3KB  |  92 lines

  1. /*
  2. **  FUNCTIONS WHICH ALLOW TURBO C 1.5 VIDEO TEXT OUTPUT
  3. **  ROUTINES TO RUN IN A TOPVIEW, DESQVIEW OR MICROSOFT
  4. **  WINDOWS WINDOW, EVEN WHEN DIRECTVIDEO = 1.
  5. */
  6.  
  7. #include <conio.h>
  8. #include <dos.h>
  9.  
  10. #define VIDEOINT    0x10    /* video BIOS interrupt */
  11.  
  12. extern struct _VIDEO {      /* UNDOCUMENTED VIDEO INFORMATION STRUCTURE */
  13.     unsigned char winleft;      /* left window coordinate (0 relative) */
  14.     unsigned char wintop;       /* top window coordinate (0 relative) */
  15.     unsigned char winright;     /* right window coordinate (0 relative) */
  16.     unsigned char winbottom;    /* bottom window coordinate (0 relative) */
  17.     unsigned char attribute;    /* text attribute */
  18.     unsigned char normattr;     /* normal attribute */
  19.     unsigned char currmode;     /* current video text mode */
  20.     unsigned char screenheight; /* bottom - top */
  21.     unsigned char screenwidth;  /* right - left */
  22.     unsigned char graphics;     /* mode type (0: text; 1: graphics) */
  23.     unsigned char needcgasync;  /* cga sync to prevent "snow" (1: yes) */
  24.     char far *videobuffer;      /* pointer to video buffer */
  25. } _video;
  26.  
  27. char TopViewActive;         /* NON-ZERO IF TOPVIEW WINDOWING IS ACTIVE */
  28.  
  29. /*
  30. **  SETUP FOR TOPVIEW/DESQVIEW VIDEO
  31. **  call at startup and whenever the video mode is changed.
  32. **  installs the shadow buffer address and sets TopViewActive.
  33. */
  34. void SetupTopView(void)
  35. {
  36.     union REGS reg;
  37.     struct SREGS sreg;
  38.  
  39.     if (_video.graphics) {                  /* if in a graphic mode */
  40.         TopViewActive = 0;                  /* TopView cannot be active */
  41.         return;
  42.     }
  43.     reg.h.ah = 0xFE;                        /* Get Video Buffer */
  44.     sreg.es = FP_SEG(_video.videobuffer);   /* assumed buffer address */
  45.     reg.x.di = FP_OFF(_video.videobuffer);
  46.     int86x(VIDEOINT, ®, ®, &sreg);    /* call video BIOS */
  47.     TopViewActive = (_video.videobuffer != MK_FP(sreg.es, reg.x.di));
  48.     if (TopViewActive)                      /* if under TopView */
  49.         _video.needcgasync = 0;             /* CGA sync is never needed */
  50.     _video.videobuffer = MK_FP(sreg.es, reg.x.di);  /* shadow buffer addr */
  51. }
  52.  
  53. /*
  54. **  UPDATE SCREEN FROM TOPVIEW VIDEO BUFFER
  55. **  (not required for DESQview)
  56. */
  57. void UpdateTopView(void)
  58. {
  59.     union REGS reg;
  60.     struct SREGS sreg;
  61.  
  62.     if (_video.graphics || !TopViewActive)  /* if graphic or not active */
  63.         return;                             /* TopView cannot be active */
  64.     reg.h.ah = 0xFF;                        /* update video buffer */
  65.     reg.x.cx = _video.screenheight * _video.screenwidth;    /* all of it */
  66.     sreg.es = FP_SEG(_video.videobuffer);   /* buffer address */
  67.     reg.x.di = FP_OFF(_video.videobuffer);
  68.     int86x(VIDEOINT, ®, ®, &sreg);    /* call video BIOS */
  69.     kbhit();                                /* yield Windows control */
  70. }
  71.  
  72. /*
  73. **  Test the TopView Video Functions.
  74. */
  75.  
  76. int main()
  77. {
  78.     int i;
  79.  
  80.     SetupTopView();
  81.     cputs("This will run fine under DOS,"
  82.         " as well as in a TopView/DESQview/Windows window!\n");
  83.     UpdateTopView();
  84.     for (i=1; i<=25; ++i) {
  85.         sleep(1);
  86.         cprintf("line %2d: %s\n", i,
  87.             "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz");
  88.         UpdateTopView();
  89.     }
  90.     return 0;
  91. }
  92.